package com.syedu.day02;

import java.util.Calendar;

/**
 * @Description java.util.Calendar,日历类,用来增强Date(Date+Calendar都是老日期/日历)
 * @createTime 2022/3/4 13:33
 * @author Administrator
 */
public class CalendarDemo {
    public static void main(String[] args) {
        //创建当前系统日历
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);

        //设置时间
        calendar.set(2002,12 - 1,12,12,12,12);

        //从日历中获取相关信息
        int year = calendar.get(Calendar.YEAR);
        System.out.println(year);

        int month = calendar.get(Calendar.MONTH) + 1;//0~11
        System.out.println(month);

        int day = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println(day);

        int hour12 = calendar.get(Calendar.HOUR);
        int hour24 = calendar.get(Calendar.HOUR_OF_DAY);
        System.out.println(hour12);
        System.out.println(hour24);

        int min = calendar.get(Calendar.MINUTE);
        System.out.println(min);

        int sec = calendar.get(Calendar.SECOND);
        System.out.println(sec);

        //注意: 绝大多数国家一周的第一天是星期日
        int week = calendar.get(Calendar.DAY_OF_WEEK);//1~7,星期天是1
        System.out.println(week);
    }
}
